import utils from "./utils";


export default (config) => {
    
    config = utils.extend({
        method: 'GET',
        callback: function() {},
        // method:'GET',
    }, config)
    if(config.method=='post'){
        config.data =  JSON.stringify(config.data);
    }
    let xhr = new XMLHttpRequest();
    xhr.open(config.method, config.url)
    xhr.setRequestHeader("Content-Type","application/json");
    xhr.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
            config.callback&&config.callback();
        }
    }
    xhr.send(config.data);
}